home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 701-725 / 716 / talincode / talincode.lha / readpixline.asm < prev    next >
Assembly Source File  |  1990-09-17  |  6KB  |  247 lines

  1. ; Read a line of pixels...
  2.  
  3. ; given an array of longwords and a bitmap pointer, and an y coord
  4. ;    read an entire scanline into the array.
  5.  
  6. ; a similar function for writing
  7.  
  8. ; void ReadPixLine(ULONG *pixvalues, struct BitMap *bmap, WORD scanline);
  9. ; #pragma regcall( ReadPixLine(a0,a1,d1) )
  10. ; void WritePixLine(ULONG *pixvalues, struct BitMap *bmap, WORD scanline);
  11. ; #pragma regcall( WritePixLine(a0,a1,d1) )
  12.  
  13.             include        'exec/types.i'
  14.             include        'graphics/gfx.i'
  15.  
  16.             xdef        _ReadPixLine
  17.             xdef        _WritePixLine
  18.  
  19. ; params are:
  20. ;    a0 - longword array
  21. ;    a1 - bitmap
  22. ;    d1 - y
  23.  
  24. SREGS        reg            d2/d3/d4/a2/a3/a4
  25.  
  26. _ReadPixLine:
  27.             movem.l        SREGS,-(sp)
  28.  
  29.             moveq        #0,d3                        ; clear upper half d3
  30.             move.w        bm_BytesPerRow(a1),d3        ; d3 <== bytes per row
  31.             mulu.w        d3,d1                        ; d1 <== plane offset
  32.  
  33.             moveq        #0,d2
  34.             move.b        bm_Depth(a1),d2                ; d2 <== plane depth
  35.             lea            bm_Planes(a1),a3            ; a3 <== Plane pointers
  36.             add.w        d2,d2
  37.             add.w        d2,d2
  38.             add.w        d2,a3
  39.  
  40.             bra.s        70$
  41.  
  42. 40$            moveq        #0,d2                        ; clear upper half d2
  43.             move.b        bm_Depth(a1),d2                ; d2 <== plane depth
  44.             subq.w        #1,d2
  45.             move.l        a3,a4                        ; a4 <== Plane pointers
  46.  
  47.             moveq        #0,d4                        ; initialize pixel values to zero
  48.             moveq        #0,d5
  49.             moveq        #0,d6
  50.             moveq        #0,d7
  51.  
  52. 50$            move.l        -(a4),a2                    ; a2 <== next bitplane pointer
  53.             move.b        (a2,d1.l),d0                ; d0 <== next pixel data word
  54.                                                     ; process 1st 4 bits in byte
  55.             add.b        d0,d0                        ; bit 8
  56.             addx.l        d4,d4                        ; into 1st pixel result
  57.             add.b        d0,d0                        ; bit 7
  58.             addx.l        d5,d5                        ; into 2nd pixel result
  59.             add.b        d0,d0                        ; bit 6
  60.             addx.l        d6,d6                        ; into 3rd pixel result
  61.             add.b        d0,d0                        ; bit 5
  62.             addx.l        d7,d7                        ; into 4th pixel result
  63.  
  64.             dbra        d2,50$                        ; loop to next plane
  65.  
  66.             movem.l        d4-d7,(a0)                    ; move to chunk array
  67.             lea            4*4(a0),a0
  68.  
  69.             moveq        #0,d2                        ; clear upper half d2
  70.             move.b        bm_Depth(a1),d2                ; d2 <== plane depth
  71.             subq.w        #1,d2
  72.             move.l        a3,a4                        ; a4 <== Plane pointers
  73.  
  74.             moveq        #0,d4                        ; initialize pixel values to zero
  75.             moveq        #0,d5
  76.             moveq        #0,d6
  77.             moveq        #0,d7
  78.  
  79. 60$            move.l        -(a4),a2                    ; a2 <== next bitplane pointer
  80.             move.b        (a2,d1.l),d0                ; d0 <== next pixel data word
  81.             lsl.b        #4,d0                        ; shift over by 4
  82.                                                     ; process 2nd 4 bits in byte
  83.             add.b        d0,d0                        ; bit 4
  84.             addx.l        d4,d4                        ; into 5th pixel result
  85.             add.b        d0,d0                        ; bit 5
  86.             addx.l        d5,d5                        ; into 6th pixel result
  87.             add.b        d0,d0                        ; bit 2
  88.             addx.l        d6,d6                        ; into 7th pixel result
  89.             add.b        d0,d0                        ; bit 1
  90.             addx.l        d7,d7                        ; into 8th pixel result
  91.  
  92.             dbra        d2,60$                        ; loop to next plane
  93.  
  94.             movem.l        d4-d7,(a0)                    ; move to chunk array
  95.             lea            4*4(a0),a0
  96.             addq        #1,d1                        ; next byte
  97.  
  98. 70$            dbra        d3,40$                        ; loop to next word
  99.  
  100.             movem.l        (sp)+,SREGS
  101.             rts
  102.  
  103. _WritePixLine:
  104.             movem.l        SREGS,-(sp)
  105.  
  106.             moveq        #0,d3                        ; clear upper half d3
  107.             move.w        bm_BytesPerRow(a1),d3        ; d3 <== bytes per row
  108.             mulu.w        d3,d1                        ; d1 <== plane offset
  109.             bra.s        70$
  110.  
  111. 40$            moveq        #0,d2                        ; clear upper half d2
  112.             move.b        bm_Depth(a1),d2                ; d2 <== plane depth
  113.             subq.w        #1,d2
  114.             lea            bm_Planes(a1),a4            ; a4 <== Plane pointers
  115.  
  116.             movem.l        (a0)+,d4-d7                    ; move to chunk array
  117.  
  118. 50$            moveq        #0,d0
  119.  
  120.             lsr.l        #1,d4
  121.             addx.b        d0,d0
  122.             lsr.l        #1,d5
  123.             addx.b        d0,d0
  124.             lsr.l        #1,d6
  125.             addx.b        d0,d0
  126.             lsr.l        #1,d7
  127.             addx.b        d0,d0
  128.  
  129.             lsl.w        #4,d0
  130.  
  131.             move.l        (a4)+,a2                    ; a2 <== next bitplane pointer
  132.             move.b        d0,(a2,d1.l),d0                ; d0 <== next pixel data word
  133.  
  134.             dbra        d2,50$                        ; loop to next plane
  135.  
  136.             moveq        #0,d2                        ; clear upper half d2
  137.             move.b        bm_Depth(a1),d2                ; d2 <== plane depth
  138.             subq.w        #1,d2
  139.             lea            bm_Planes(a1),a4            ; a4 <== Plane pointers
  140.  
  141.             movem.l        (a0)+,d4-d7                    ; move to chunk array
  142.  
  143. 60$            moveq        #0,d0
  144.  
  145.             lsr.l        #1,d4
  146.             addx.b        d0,d0
  147.             lsr.l        #1,d5
  148.             addx.b        d0,d0
  149.             lsr.l        #1,d6
  150.             addx.b        d0,d0
  151.             lsr.l        #1,d7
  152.             addx.b        d0,d0
  153.  
  154.             move.l        (a4)+,a2                    ; a2 <== next bitplane pointer
  155.             or.b        d0,(a2,d1.l),d0                ; d0 <== next pixel data word
  156.  
  157.             dbra        d2,60$                        ; loop to next plane
  158.  
  159.             addq        #1,d1                        ; next byte
  160. 70$            dbra        d3,40$                        ; loop to next word
  161.  
  162.             movem.l        (sp)+,SREGS
  163.             rts
  164.  
  165.             end
  166.  
  167.  
  168.  
  169.  
  170.  
  171. SREGS        equr        d2-d4/a2-a5
  172.  
  173. _ReadPixLine:
  174.             movem.l        SREGS,-(sp)
  175.  
  176.             mulu.w        #bm_BytesPerRow(a1),d1        ; d1 <== plane offset
  177.  
  178.             moveq        #0,d2                        ; clear upper half d2
  179.             move.b        bm_Depth(a1),d2                ; d2 <== plane depth
  180. ; REM: Check for small number of planes and do special case code
  181.  
  182.             lea            bm_Planes(a1),a5            ; a5 <== Plane pointers
  183.  
  184.             move.l        d2,d4                        ; d4 <== copy of depth
  185.             bra.s        30$                            ; start the loop
  186.  
  187.             moveq        #1,d3                        ; shift d3 from 1 to 0x8000000
  188.  
  189. 10$            move.l        (a5)+,a2                    ; a2 <== next biplane pointer
  190.             add.l        d1,a2                        ; a2 <== addr of pixel data word
  191.  
  192.             moveq        #0,d5                        ; clear upper half d5
  193.             moveq.w        bm_BytesPerRow(a1),d5        ; get bytes per row
  194.             lsr.w        #1,d5                        ; d5 = numbver of words per row
  195.  
  196.             move.l        a0,a4                        ; address of longword array
  197.             sub.l        #4,a4                        ; start BEFORE array
  198.  
  199.             bra.s        20$
  200.  
  201. 12$            addq        #4,a4                        ; add to array pointer
  202.             add.w        d0,d0                        ; move top bit into carry
  203.             bcc            12$                            ; if carry clear, then continue
  204.  
  205.             beq.s        13$
  206.             add.l        d3,(a4)                        ; else add bit into pixel val
  207.             bra.s        12$
  208. 13$            add.l        d3,(a4)                        ; else add bit into pixel val
  209.  
  210.             move.l        a6,a4                        ; and update to next row
  211.  
  212. 20$            move.w        (a2)+,d0                    ; d0 <== next pixel data word
  213.             move.l        a4,a6                        ; a6 <== lwords for this pixel wd
  214.             add.w        #16*4,a6                    ; a6 <== lwords for next pixel wd
  215.             beq.s        20$                            ; if no bits set, then next plane
  216.  
  217.             dbra        d5,12$                        ; loop for next pixel data word
  218.  
  219.             add.l        d3,d3                        ; shift addition bit over 1
  220. 30$            dbra        d4,10$
  221.  
  222.             movem.l        (sp)+,SREGS
  223.             rts
  224.  
  225.             end
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. ; Read a line of pixels...
  233.  
  234. ; given an array of longwords and a bitmap pointer, and an y coord
  235. ;    read an entire scanline into the array.
  236.  
  237.             include        'exec/types.i'
  238.             include        'graphics/gfx.i'
  239.  
  240. ; params are:
  241. ;    a0 - longword array
  242. ;    a1 - bitmap
  243. ;    d1 - y
  244.  
  245. SREGS        equr        d2-d4/a2-a6
  246.  
  247.